﻿using IterationLife.Educations.Models;
using Util;

namespace IterationLife.PlatformBackEnd.AppServices.Dtos.Educations {
    /// <summary>
    /// 课程大纲数据传输对象扩展
    /// </summary>
    public static class SyllabusDtoExtension {        
        /// <summary>
        /// 转换为课程大纲实体
        /// </summary>
        /// <param name="dto">课程大纲数据传输对象</param>
        public static Syllabus ToEntity( this SyllabusDto dto ) {
            if( dto == null )
                return new Syllabus();
            return new Syllabus( dto.Id.ToGuid() ,dto.Path,dto.Level.SafeValue() ) {
                ParentId = dto.ParentId.ToGuidOrNull(),
                Name = dto.Name,
                TextBookId = dto.TextBookId,
                ContentResourceId = dto.ContentResourceId,
                Enabled = dto.Enabled,
                SortId = dto.SortId,
                CreationTime = dto.CreationTime,
                CreatorId = dto.CreatorId,
                LastModificationTime = dto.LastModificationTime,
                LastModifierId = dto.LastModifierId,
                IsDeleted = dto.IsDeleted,
                Version = dto.Version
            };
        }
        
        /// <summary>
        /// 转换为课程大纲数据传输对象
        /// </summary>
        /// <param name="entity">课程大纲实体</param>
        public static SyllabusDto ToDto( this Syllabus entity ) {
            if( entity == null )
                return new SyllabusDto();
            return new SyllabusDto {
                Id = entity.Id.SafeString(),
                ParentId = entity.ParentId.SafeString(),
                Name = entity.Name,
                TextBookId = entity.TextBookId,
                ContentResourceId = entity.ContentResourceId,
                Level = entity.Level,
                Enabled = entity.Enabled,
                SortId = entity.SortId,
                Path = entity.Path,
                CreationTime = entity.CreationTime,
                CreatorId = entity.CreatorId,
                LastModificationTime = entity.LastModificationTime,
                LastModifierId = entity.LastModifierId,
                IsDeleted = entity.IsDeleted,
                Version = entity.Version
            };
        }
    }
}
